# encoding: UTF-8
class SessionsController < ApplicationController
  skip_before_filter :authorize
  def new
    @categories = Category.all
    @hot_books = Book.search_hot_book()    
  end

  def create
    if params[:login]
      if user = User.authenticate(params[:name], params[:password])
        session[:user_id] = user.id
        redirect_to account_new_url
      else
        redirect_to login_url, :alert => "Tài khoản hoặc mật khẩu không đúng!"
      end
    else
      if params[:signup]
        redirect_to new_user_path
      else
        redirect_to login_url
      end
    end

  end

  def destroy
    session[:user_id] = nil
    redirect_to login_url, :notice => "Đã thoát!"
  end

end